package e.odbo.data.sample.attach;


import com.openbravo.data.basic.BasicException;
import e.odbo.data.dao.BaseDAO;
import e.odbo.data.dao.EntityManager;
import e.odbo.data.dao.table.TableDefinition;
import e.odbo.data.dao.table.Field;
import com.openbravo.data.loader.serialize.Datas;
import e.odbo.data.format.Formats;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.DataRead;


public class OdbOAttachDAO extends BaseDAO<OdbOAttach> {

    public OdbOAttachDAO(EntityManager entityManager) {
        super(entityManager);
    }

    // tableDefinition table:	odbo_attach 	build time :2019-07-01 14:54:29.915

    @Override
    public TableDefinition getTable() {
        TableDefinition odbo_attachTableDefinition=new TableDefinition("odbo_attach" ,new Field[]{
                new Field(OdbOAttach.ID,Datas.STRING,Formats.STRING),//(PK)
                new Field(OdbOAttach.CURDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),//(notNull)
                new Field(OdbOAttach.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP),//
                new Field(OdbOAttach.OWNER,Datas.STRING,Formats.STRING),//(notNull)
                new Field(OdbOAttach.ATTACHTYPE,Datas.INT,Formats.INT),//(notNull)
                new Field(OdbOAttach.ATTACH,Datas.BLOB,Formats.NULL),//(notNull)
                new Field(OdbOAttach.MEMO,Datas.STRING,Formats.STRING)//
        }, new int[] {0}
        );
        return odbo_attachTableDefinition;
    }

    @Override
    public void writeInsertValues(DataWrite dp,OdbOAttach obj) throws BasicException {
        dp.setString(1,obj.getId());
        dp.setTimestamp(2,obj.getCurdate());
        dp.setTimestamp(3,obj.getLastmodified());
        dp.setString(4,obj.getOwner());
        dp.setInteger(5,obj.getAttachtype());
        dp.setBlob(6,obj.getAttach());

        dp.setString(7,obj.getMemo());
    }

    @Override
    public Class getSuportClass() {
        return OdbOAttach.class;
    }

    public OdbOAttach readValues(DataRead dr, OdbOAttach obj) throws BasicException {
        if(obj==null)
            obj = new OdbOAttach();
        obj.setId(dr.getString(1));
        obj.setCurdate(dr.getTimestamp(2));
        obj.setLastmodified(dr.getTimestamp(3));
        obj.setOwner(dr.getString(4));
        obj.setAttachtype(dr.getInteger(5));
        obj.setAttach(dr.getBlob(6));

        obj.setMemo(dr.getString(7));
        return obj;
    }
}